package com.neu.controller;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neu.entity.Fmeditem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neu.entity.RegistLevel;
import com.neu.service.RegistLevelService;
import com.neu.util.JsonResult;
import com.neu.util.ResultCode;




@CrossOrigin
@RestController
@RequestMapping("/his/registlevel")
public class RegistLevelController {
	public static final Integer ok = 200;
		@Autowired
		private RegistLevelService registLevelService;
//		添加挂号级别
		@PostMapping("/add_register")
		public JsonResult<Boolean> addRegistLevel(@RequestBody String body) {
			RegistLevel registLevel=JSON.parseObject(body,RegistLevel.class);
			boolean save =  registLevelService.addRegistLevel(registLevel);
			if(save) {
				return new JsonResult<Boolean>(ResultCode.SUCCESS,save);
			}else {
				return new JsonResult<Boolean>(ResultCode.INSERT_ERROR,save);
			}
				
		}
//		删除挂号级别通过id
		@PostMapping("/delete_register")
		public JsonResult<Boolean> delRegistLevel(@RequestBody  String body) {
			JSONObject json = JSON.parseObject(body);
			int id = (int) json.get("id");
			boolean flag= registLevelService.delRegistLevel(id);
			System.out.println(json);
			return new JsonResult<Boolean>(ResultCode.SUCCESS,flag);
				
		}
//		修改挂号级别
		@PostMapping("/update_register")
		public JsonResult<Boolean> updateRegistLevel(@RequestBody String body) {
			RegistLevel registLevel=JSON.parseObject(body, RegistLevel.class);
			boolean upd= registLevelService.updateRegistLevel(registLevel);
			return new JsonResult<Boolean>(ResultCode.SUCCESS,upd);
				
		}
//		分页查询挂号级别
		@GetMapping("/get_register")
		public JsonResult<List<RegistLevel>> pageRegistLevel(@RequestParam int page,@RequestParam int limit) {
			List<RegistLevel> list=registLevelService.pageRegistLevel(page,limit);
			return new JsonResult<List<RegistLevel>>(ResultCode.SUCCESS,list);
		}
		
}
